package com.imax.center.task;

import com.alibaba.fastjson.JSONArray;
import com.imax.center.common.Result;
import com.imax.center.service.H3yunService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 事件数据统计任务
 */
@Slf4j
@Component
public class EventStatTask {

    @Autowired
    private H3yunService h3yunService;

    /**
     * 每天凌晨0点10分 执行写入昨日各医院污水处理量
     */
    @Scheduled(cron = "0 10 0 * * ?")
    public void autoAddYesterdayW00000Count() {
        log.info("开始执行【统计昨日各医院污水处理量】任务");
        try {
            JSONArray list = h3yunService.getYesterdayW00000Count().getData();
            log.info("查询到{}条记录", list.size());
            
            Result<?> result = h3yunService.addYesterdayW00000Count(list);

            log.info("【写入昨日各医院污水处理量】成功: {}", result.getMsg());
        } catch (Exception e) {
            log.error("【统计昨日各医院污水处理量】任务异常: ", e);
        }
        log.info("【统计昨日各医院污水处理量】任务结束");
    }
    
}